package deliciouse.biz.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import deliciouse.biz.MessagesBiz;
import deliciouse.dao.MessagesDao;
import deliciouse.entity.Messages;
import deliciouse.util.MybatisUtil;

public class MessagesBizImpl implements MessagesBiz{

	@Override
	public List<Messages> fetchByDate(int pageNum, int pageSize) {
		SqlSession sess = MybatisUtil.OpenSession();
		try {
			MessagesDao dao = sess.getMapper(MessagesDao.class);
			List<Messages> messageslist = dao.fetchByDate((pageNum-1)*pageSize, pageSize);
			return messageslist;
		} finally {
			sess.close();
		}
	}

	@Override
	public boolean addMessage(Messages messages) {
		SqlSession sess = MybatisUtil.OpenSession();
		try {
			MessagesDao dao = sess.getMapper(MessagesDao.class);
			dao.addMessage(messages);
			sess.commit();
			return true;
		} finally {
			sess.close();
		}
	}

	@Override
	public int MessageMaxRows() {
		SqlSession sess = MybatisUtil.OpenSession();
		try {
			MessagesDao dao = sess.getMapper(MessagesDao.class);
			int rows =dao.MessageMaxRows();
			return rows;
		} finally {
			sess.close();
		}
	}

}
